#include "signup.srpc.h"
#include "workflow/WFFacilities.h"
#include <iostream>
using namespace srpc;

static WFFacilities::WaitGroup wait_group(1);

void sig_handler(int signo)
{
	wait_group.done();
}

static void signup_done(RespSignup *response, srpc::RPCContext *context)
{
	std::cout << "code = " << response->code()
	          << " information = " << response->information()
			  << "\n";
}
int main()
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;
	// 指明服务端的ip和端口
	const char *ip = "127.0.0.1";
	unsigned short port = 1412;
	// client 它是服务端在客户端的代理
	UserService::SRPCClient client(ip, port);

	// RepSignup是函数的参数
	ReqSignup req;
	req.set_username("changfeng");
	req.set_password("12345");
	// 方案1 client里面的Signup函数 是异步的
	// 当收到返回值的时候，signup_done会被调用
	//client.Signup(&req, signup_done);
	// 方案2 client可以创建一个rpc任务，放入序列中执行
	auto task = client.create_Signup_task(signup_done); // 创建任务
	task->serialize_input(&req); //设置任务的属性
	task->start(); //启动任务
	wait_group.wait();
	google::protobuf::ShutdownProtobufLibrary();
	return 0;
}
